package com.example.diancai.ai.game2048;

import com.alibaba.fastjson2.JSON;
import com.example.diancai.dto.Vec3DTO;
import com.example.diancai.dto.Vec3StatusDTO;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class Tile {
    public int x;
    public int y;
    public int value;

    /**
     * 状态
     */
    public List<Vec3StatusDTO> status=new ArrayList<>();

    public Vec3DTO previousPosition;
    public List<Tile> mergedFrom;
    boolean marked;


    public Tile(Vec3DTO position) {
        this.x = (int) position.getX();
        this.y = (int) position.getY();
        this.value = (int) position.getZ();
        this.previousPosition = null;
        this.mergedFrom = null;
    }

    public void savePosition() {
        this.previousPosition = new Vec3DTO(this.x, this.y, this.value, new ArrayList<>());
    }

    public void updatePosition(Vec3DTO position) {
        this.x = (int) position.getX();
        this.y = (int) position.getY();
    }

    public Tile clone() {
        // 保持原有注释不变
        Tile tile = new Tile(new Vec3DTO(this.x, this.y, this.value,status));
        tile.status= JSON.parseArray(JSON.toJSONString(this.status), Vec3StatusDTO.class);
        return tile;
    }
}
